package com.briup.mt.web.controller;

import com.briup.mt.bean.Greenhouse;
import com.briup.mt.dao.GreenhouseMapper;
import com.briup.mt.service.GreenhouseService;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/greenhouse")
@Validated
public class GreenhouseController {

    @Autowired
    private GreenhouseService greenhouseService;

    @GetMapping("findAll")
    public Message query(String name,String datasetId){
        List<Greenhouse> list = greenhouseService.query(name,datasetId);
        return MessageUtil.success(list);
    }

    @DeleteMapping("deleteById")
    public Message deleteById(long id) {
        greenhouseService.deleteById(id);
        return MessageUtil.success("删除成功！");
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Greenhouse greenhouse){
        greenhouseService.saveOrUpdate(greenhouse);
        return MessageUtil.success("操作成功");
    }
}
